REPOROOT=../
# Use make help, to see the available rules
include ../.make.defaults


setup::
	@# Help: Recursively make $@ all subdirs 
	$(MAKE) RULE=$@ .recurse

clean::
	# Clean up workflows common virtual environment.
	rm -rf venv || true
	rm -rf *.back || true
	@# Help: Recursively make $@ all subdirs 
	$(MAKE) RULE=$@ .recurse

setup::
	@# Help: Recursively make $@ in subdirs 
	$(MAKE) RULE=$@ .recurse

build::
	@# Help: Recursively make $@ in subdirs 
	$(MAKE) RULE=$@ .recurse
venv::
	@# Help: Recursively make $@ in subdirs 
	$(MAKE) RULE=$@ .recurse

image:: 
	@# Help: Recursively make $@ in all subdirs 
	@$(MAKE) RULE=$@ .recurse

publish:: 
	@# Help: Recursively make $@ in all subdirs 
	@$(MAKE) RULE=$@ .recurse

test-image:: 
	@# Help: Recursively make $@ in all subdirs 
	@$(MAKE) RULE=$@ .recurse

test:: 
	@# Help: Recursively make $@ in all subdirs 
	@$(MAKE) RULE=$@ .recurse

test-src::
	@# Help: Recursively make $@ in all subdirs 
	$(MAKE) RULE=$@ .recurse

kind-load-image::
	@# Help: Recursively make $@ in all subdirs 
	$(MAKE) RULE=$@ .recurse

docker-load-image::
	@# Help: Recursively make $@ in all subdirs
	$(MAKE) RULE=$@ .recurse

docker-save-image::
	@# Help: Recursively make $@ in all subdirs 
	$(MAKE) RULE=$@ .recurse

workflow-venv::
	@# Help: Recursively make $@ in subdirs
	$(MAKE) RULE=$@ .recurse	

setup::
	@# Help: Recursively make $@ in subdirs
	$(MAKE) RULE=$@ .recurse

workflow-test::
	@# Help: Recursively make $@ in subdirs
	$(MAKE) RULE=$@ .recurse

workflow-build::
	@# Help: Recursively make $@ in subdirs
	$(MAKE) RULE=$@ .recurse

workflow-upload::
	@# Help: Recursively make $@ in subdirs
	$(MAKE) RULE=$@ .recurse

set-versions::
	@# Help: Recursively make $@ in all subdirs
	make set-pkg-version
	@$(MAKE) RULE=$@ .recurse

set-pkg-version:
	@# Help: Set tag for this package and its dependencies
	if [ -e pyproject.toml ]; then					\
		cat pyproject.toml | sed -e 's/^version[ ]*=.*/version = "'${TRANSFORMS_PKG_VERSION}'"/' > tt; \
		mv tt pyproject.toml; \
	fi
	#echo $(DPK_VERSION)
	if [ -e requirements.txt ]; then					\
		cat requirements.txt |	sed -e 's/data-prep-toolkit\([=><~][=]\).*/data-prep-toolkit\1$(DPK_VERSION)/' > tt; \
		mv tt requirements.txt; \
	fi
	if [ -e requirements-ray.txt ]; then					\
		cat requirements-ray.txt |	sed -e 's/data-prep-toolkit\[ray\]\([=><~][=]\).*/data-prep-toolkit\[ray\]\1$(DPK_VERSION)/' > tt; \
		mv tt requirements-ray.txt; \
	fi


build-pkg-dist:
	@# Help: Build package wheel 
	# Only needs to build the whl
	-rm -fr build dist data_prep_toolkit.egg-info
	git show --no-patch > universal/web2parquet/gitshow.txt
	$(MAKE) BUILD_WHEEL_EXTRA_ARG=-w .defaults.build-dist
	rm universal/web2parquet/gitshow.txt

test-pkg-dist:
	@# Help: Setup environment and run unit tests for all transforms.
	-rm -fr venv
	python -m venv venv
	source venv/bin/activate && $(PYTHON) -m pip  install '$(REPOROOT)/data-processing-lib/dist/data_prep_toolkit-$(DPK_VERSION)-py3-none-any.whl[dev,ray]'
	source venv/bin/activate && $(PYTHON) -m pip  install 'dist/data_prep_toolkit_transforms-$(TRANSFORMS_PKG_VERSION)-py3-none-any.whl[ray,all]'
	source venv/bin/activate && pip install pytest scancode-toolkit
	for T in $(shell find . | grep '/test$$') ; do \
		if [[ "$$T" =~ venv ]] || [[ "$$T" =~ malware ]] || [[ "$$T" =~ code_profiler ]] || [[ "$$T" =~ header_cleanser ]] || [[ "$$T" =~ chain ]] || [[ "$$T" =~ html2parquet ]] || [[ "$$T" =~ noop ]]; then \
			echo ; \
		else \
		    echo "running unit test on: $$T" ; \
			source venv/bin/activate && cd $$T && $(PYTEST) . --ignore-glob="*_spark.py" ; \
			cd ../../.. ; \
		fi; \
    done;
	@# Help: Setup environment and run unit tests for all transforms

publish-dist :: .defaults.publish-dist

publish-testpypi:
	## when installing from testpypi, make sure you install the dependecies first (pip install data-prep-toolkit)
	## and then use extra-url-index to install this package:
	## pip install --extra-index-url https://test.pypi.org/simple/ 'data-prep-toolkit-transforms[all]==x.x.x.devx'
	twine upload --repository testpypi dist/*

